package com.mystyle.le.qjnewsproject.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;

/**
 * Created by le on 2016/10/8.
 */
public class HzCustomView extends HorizontalScrollView {

    public HzCustomView(Context context) {
        super(context);
    }

    public HzCustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    private float xDistance, yDistance, xLast, yLast;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                xDistance = yDistance = 0;
                yLast = ev.getY();
                xLast = ev.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                float currentX = ev.getX();
                float currentY = ev.getY();

                xDistance += Math.abs(currentX - xLast);
                yDistance += Math.abs(currentY - yLast);

                xLast = currentX;
                yLast = currentY;
                if (xDistance > yDistance) {
                    return false;
                }
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}
